<template>
	<view class="container">
		<u-navbar title="专业资料" :title-bold='true' background="#6EC9E1" :is-fixed="true" z-index='999'
			:border-bottom="false" title-color="#FFF" back-icon-color="#FFF">
		</u-navbar>

		<view class="card">
			<view class="userInfo">
				<view class="c-u">
					<view class="name">{{userInfo.username||"名称"}}</view>
					<view class="speciality">{{userInfo.speciality||'专业'}}</view>
				</view>
				<view class="c-u c-e">
					<image src="@/static/img/mine/yiyuan.png" mode="widthFix"></image>
					<view>{{userInfo.institution||'机构'}}</view>
				</view>
			</view>
			<u-avatar size='140' mode="square" :src="userInfo.avatar_work"></u-avatar>
		</view>

		<view class="card " v-if="userInfo.work && userInfo.work.length>0">
			<view class="experience">
				<view class="title">工作历程</view>
				<view class="item" v-for="(item,index) in userInfo.work" :key="index">
					<view class="line-dot">
						<view class="dot"></view>
						<u-line v-if="index<userInfo.work.length-1" direction='col' length='100%'
							color="#D8D8D8"></u-line>
					</view>
					<text class="time">{{item.start_time +'~'+ item.end_time }}</text>
					<view class="work">
						{{item.company||''}}
					</view>
				</view>
			</view>
		</view>


		<view class="card" v-if="userInfo.bio">
			<view class="expertise">
				<view class="title">擅长方向</view>
				<p>{{userInfo.bio||'例如：睡眠呼吸疾病、咽、喉和咽旁间隙微创手术、嗓音外科、咽喉气管狭窄、吞咽障碍等咽喉疾病，喉癌功能保全、头颈肿瘤外科手术。'}}</p>
			</view>
		</view>

		<view class="card " v-if="userInfo.certificate">
			<view class="title">专业证书</view>
			<image class="certificate" :src="userInfo.certificate" mode="widthFix"></image>
		</view>

	</view>
</template>

<script>
	import {
		getDoctorInfo,
		chat
	} from '@/api/index.js'
	export default {
		data() {
			return {
				userInfo: {},
				other: false,
				doctor_id: ''
			}
		},
		onLoad(e) {
			if (e.id) {
				this.doctor_id = e.id
			}
			if (e.user) {
				this.ws.sid = `sid=${e.user}&type=2`
				this.ws.sid = encodeURIComponent(this.ws.sid)
				this.ws.logout()
			}
			if (e.userInfo) {
				this.userInfo = JSON.parse(e.userInfo)
			} else {
				this.init(e.id)
			}
		},

		onShareAppMessage() {
			let pages = getCurrentPages(); //获取当前页面栈的信息
			let currentPage = pages[pages.length - 1]; //获取到当前页面栈中最后一个页面的索引
			let user = this.ws.getUserInfo()
			return {
				title: "生活咨询，3次回访，放心，看得见！",
				path: currentPage.route + `?id=${this.doctor_id}&user=${user.user_id}` //后面是路径上要传递的参数
			}
		},
		methods: {
			init(id) {
				let that = this
				let user = that.ws.getUserInfo()
				if (user.id == id) {
					that.other = true
				}
				getDoctorInfo({
					'doctor_id': id
				}).then(res => {
					if (res.code == 1) {
						that.userInfo = res.data.info
					}
				})
			},


			tochat(id) {
				let that = this
				chat({
					'user_id': id
				}).then(res => {
					if (res.code == 1) {
						that.ws.tochat(res.data.session_id)
					}
				})
			},
		}

	}
</script>

<style lang="less">
	.btu {
		display: flex;
		justify-content: space-around;
		align-items: center;
		margin-top: 20px;

		u-button {
			min-width: 30%;
		}
	}

	u-avatar {
		border-radius: 5px;
	}

	.container {
		background: url('@/static/img/mine/header-bg.png');
		background-size: 100% 22vh;
		background-repeat: no-repeat;
		padding: 30rpx;
		background-color: #EEE;
		height: 100vh;
		font-size: 15px;
		color: #333333;

		.title {
			font-size: 20px;
			margin-top: 10rpx;
		}

		.card {
			width: 100%;
			margin-top: 20rpx;
			background-color: #FFF;
			border-radius: 18rpx;
			padding: 30rpx 40rpx;
			min-height: 86px;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.certificate {
				width: 74px;
				border-radius: 6px;
				filter: blur(1px)
			}

			.idcard {
				height: 60px;
				width: 85px;
				border-radius: 4.51px;
			}

			.c-u {
				display: flex;
				align-items: flex-end;

				.name {
					font-size: 24px;
					margin-right: 20rpx;
				}

				.speciality {
					font-size: 13px;
				}
			}

			.c-e {
				align-items: center;
				font-size: 12px;
				color: #666;
				line-height: 30px;

				image {
					width: 11px;
					margin-right: 20rpx;
				}
			}

			.experience {
				width: 100%;

				.title {
					margin-bottom: 20px;
				}

				.item {
					position: relative;
					display: flex;
					width: 100%;

					.line-dot {
						height: 57px;
						display: flex;
						flex-direction: column;
						align-items: center;
						margin-right: 20px;

						.dot {
							height: 15rpx;
							width: 15rpx;
							background-color: #D8D8D8;
							border-radius: 50%;
						}
					}

					.time {
						font-size: 13px;
						line-height: 10px;
						position: relative;
						top: -2rpx;
						color: #999999;
					}

					.work {
						width: 100%;
						position: absolute;
						top: calc(50% - 8px);
						left: 27px;
						font-size: 14px;
						color: #333333;
					}
				}
			}

			.expertise {
				p {
					color: #999999;
					line-height: 30px;
					margin-top: 10rpx;
				}
			}
		}
	}
</style>